package haizhi.fruitmall.service.impl;

import haizhi.fruitmall.dao.mapper.ShopMapper;
import haizhi.fruitmall.pojo.po.Shop;
import haizhi.fruitmall.pojo.po.ShopExample;
import haizhi.fruitmall.service.ShopService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ShopServiceImpl implements ShopService {

	@Autowired
	private ShopMapper shopMapper;

	@Override
	public void addShop(Shop shop) {
		shopMapper.insertSelective(shop);
	}

	@Override
	public void deleteGoods(String shop_id, Long goods_id) {
		ShopExample shopExample = new ShopExample();
		ShopExample.Criteria criteria = shopExample.createCriteria();
		criteria.andGoodsIdEqualTo(goods_id);
		criteria.andShopIdEqualTo(shop_id);
		shopMapper.deleteByExample(shopExample);
	}

	@Override
	public void updatePurchaseNum(Shop shop, String shop_id, Long goods_id) {
		ShopExample shopExample = new ShopExample();
		ShopExample.Criteria criteria = shopExample.createCriteria();
		criteria.andGoodsIdEqualTo(goods_id);
		criteria.andShopIdEqualTo(shop_id);
		shopMapper.updateByExampleSelective(shop, shopExample);
	}

	@Override
	public List<Shop> getShopsByShopId(String shop_id) {
		ShopExample shopExample = new ShopExample();
		ShopExample.Criteria criteria = shopExample.createCriteria();
		criteria.andShopIdEqualTo(shop_id);
		return shopMapper.selectByExample(shopExample);
	}
}
